package com.zf.shuashua.advert;

import com.vise.xsnow.http.callback.ACallback;
import com.zf.shuashua.api.HttpData;
import com.zf.shuashua.bean.AdvertInfo;
import com.zf.shuashua.bean.AdvertReport;
import com.zf.shuashua.bean.BaseData;

/**
 * 自身广告数据上报
 */
public class AdvertReportManager {

    private static AdvertReportManager instance;

    private AdvertReportManager() {

    }

    public static AdvertReportManager getInstance() {
        if (null == instance) {
            synchronized (AdvertReportManager.class) {
                if (null == instance) {
                    instance = new AdvertReportManager();
                }
            }
        }
        return instance;
    }

    /**
     * @param advertInfo 广告bean
     * @param eventType  执行事件, video_start;video_pause;video_end; video_stop, image_show; video_click; image_click
     * @param type       广告位，1.开屏 2.信息流 3.签到 4.看视频 5.开启自动播放
     * @return
     */
    public void reportAdvertAction(AdvertInfo advertInfo, AdvertReport.EventType eventType, String type) {
        AdvertReport advertReport = new AdvertReport();
        advertReport.setPlan_id(advertInfo.plan_id);
        advertReport.setUuid(advertInfo.uuid);
        advertReport.setEvent(eventType);
        advertReport.setClient(1);
        advertReport.setType(type);
        reportAdvertAction(advertReport);
    }

    public void reportAdvertAction(AdvertInfo advertInfo, AdvertReport.EventType eventType, String type, ACallback<BaseData> callback) {
        AdvertReport advertReport = new AdvertReport();
        advertReport.setPlan_id(advertInfo.plan_id);
        advertReport.setUuid(advertInfo.uuid);
        advertReport.setEvent(eventType);
        advertReport.setClient(1);
        advertReport.setType(type);
        reportAdvertAction(advertReport, callback);
    }

    /**
     * 首页视屏信息流
     */
    public void reportAdvertAction(int plan_id, String uuid, AdvertReport.EventType eventType, String type) {
        AdvertReport advertReport = new AdvertReport();
        advertReport.setPlan_id(plan_id);
        advertReport.setUuid(uuid);
        advertReport.setEvent(eventType);
        advertReport.setClient(1);
        advertReport.setType(type);
        reportAdvertAction(advertReport);
    }

    public void reportAdvertAction(int plan_id, String uuid, AdvertReport.EventType eventType, String type, ACallback<BaseData> callback) {
        AdvertReport advertReport = new AdvertReport();
        advertReport.setPlan_id(plan_id);
        advertReport.setUuid(uuid);
        advertReport.setEvent(eventType);
        advertReport.setClient(1);
        advertReport.setType(type);
        reportAdvertAction(advertReport, callback);
    }

    /**
     * @param advert 广告上报bean
     */
    public void reportAdvertAction(AdvertReport advert, ACallback<BaseData> callback) {
        HttpData.getInstance().reportAdvertAction(advert, callback);
    }

    /**
     * @param advert 广告上报bean
     */
    public void reportAdvertAction(AdvertReport advert) {
        HttpData.getInstance().reportAdvertAction(advert, new ACallback<BaseData>() {
            @Override
            public void onSuccess(BaseData data) {

            }

            @Override
            public void onFail(int errCode, String errMsg) {
            }
        });
    }

}
